Developer Documentation
PATHJava Developer Documentation > Mac OS Runtime for Java > JManager > Programming With JManager


Beginning a Java Runtime Session

On the Mac OS platform, the Java runtime session is defined by the JMSessionRef object. To instantiate this object, you must call the function JMOpenSession. Listing 1-1 gives an example of creating a session.

Listing 1-1 Creating a session

static JMSessionRef theSession;

static Boolean initializeMRJ()
{
        
    JMSessionCallbacks sessionCallbacks = {
        kJMVersion,         /* the current version */
        MyStandardOutput,   /* designated standard output */
        MyStandardError,    /* designated standard error */
        MyStandardIn        /* designated standard input */
        MyExit              /* System.exit handler */
        MyAuthenticate      /* URL Authentication handler */
        MyLowMem            /* Low memory condition handler */
    };
    
    return JMOpenSession(&theSession, eJManager2Defaults,
                        eCheckRemoteCode, &sessionCallbacks,
                        kTextEncodingMacRoman, 0) == noErr;
}

The instantiated JMSessionRef object is referenced by the value of theSession . Other JManager functions require you to pass this value to identify the session. (You can create more than one instantiation of the Java runtime environment if you wish.) Note that the JMSessionCallbacks structure you pass contains a field indicating the version of JManager you are using in your program. You should always set this value to kJMVersion . Setting this value prevents your program from accessing older (possibly incompatible) JManager functions.

The text encoding you specify when calling JMOpenSession ( kTextEncodingMacRoman in this example) indicates the encoding used for any data sent to the designated standard output or standard error.

Session and Security Options

When calling JMOpenSession , you pass two parameters that indicate the desired session options, and whether you want to use the code verifier.

The example in Listing 1 passes eJManager2Defaults , which selects all the default settings. See Runtime Session Options for a list of the available options.

After calling JMOpenSession , you can read or modify the code verifier setting by calling the functions JMGetVerifyMode or JMSetVerifyMode respectively.

Callbacks

The data structure you must pass to the JMOpenSession function is a set of callback functions to handle console input and output, calls to exit from a Java application, low memory conditions, and URL authentication.

For more information about the session callback structure, see Session Callbacks Structure.


© 1998 Apple Computer, Inc. — (Last Updated 3 Dec 98)